package com.pacy.pacybaseproject.activitys;

import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioGroup;

import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.FragmentUtils;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.pacy.pacybaseproject.BR;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.base.BaseXActivity;
import com.pacy.pacybaseproject.beans.TabBean;
import com.pacy.pacybaseproject.databinding.ActivityTravelBinding;
import com.pacy.pacybaseproject.fragments.BusFragment;
import com.pacy.pacybaseproject.fragments.CyclingFragment;
import com.pacy.pacybaseproject.fragments.OneCodeFragment;
import com.pacy.pacybaseproject.fragments.TaxiFragment;
import com.pacy.pacybaseproject.viewmodels.TravelViewModel;
import com.xuexiang.xui.utils.StatusBarUtils;
import com.xuexiang.xui.utils.ViewUtils;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.utils.ScreenUtil;

/**
 * @author PACY
 * @date 2023/12/20
 * description: 出行
 */
public class TravelActivity extends BaseXActivity<ActivityTravelBinding, TravelViewModel> {
    public int initTabPosition=0;
    private ArrayList<CustomTabEntity> tabs = new ArrayList<>();
    private List<Fragment> fragments=new ArrayList<>();


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_travel;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        initTab();
        if(getIntent().getExtras()!=null){
            initTabPosition=getIntent().getExtras().getInt("initTabPosition",0);
        }
        LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,StatusBarUtils.getStatusBarHeight(TravelActivity.this));
        binding.view.setLayoutParams(params);
        fragments.add(OneCodeFragment.newInstance("一码通行"));
        fragments.add(BusFragment.newInstance("公交"));
        fragments.add(TaxiFragment.newInstance("打车"));
        fragments.add(CyclingFragment.newInstance("骑行"));
        FragmentUtils.add(getSupportFragmentManager(),fragments.get(0),R.id.fly);
        FragmentUtils.add(getSupportFragmentManager(),fragments.get(1),R.id.fly);
        FragmentUtils.add(getSupportFragmentManager(),fragments.get(2),R.id.fly);
        FragmentUtils.add(getSupportFragmentManager(),fragments.get(3),R.id.fly);
        FragmentUtils.showHide(initTabPosition,fragments);

        binding.tabLayout.setCurrentTab(initTabPosition);
    }

    private void initTab(){
        tabs.add(new TabBean("一码通行"));
        tabs.add(new TabBean("公交"));
        tabs.add(new TabBean("打车"));
        tabs.add(new TabBean("骑行"));
        binding.tabLayout.setTabData(tabs);
        binding.tabLayout.setCurrentTab(0);
        binding.tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                FragmentUtils.showHide(position,fragments);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }
}
